package com.system.server.impl;

import com.system.dao.AdminDao;
import com.system.pojo.College;
import com.system.pojo.Course;
import exception.AddCourseError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: E-mail:
 * @Version: 创建时间：2019年04月14日15:15
 * @Description: <描述>
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class AdminServiceImpl implements com.system.server.AdminService {

    @Autowired
    private AdminDao adminDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public List<College> findCollege() {
        return adminDao.selectCollege();
    }
    @Override
    public boolean checkCourseID(Integer courseID) {
        Course course = adminDao.selectCourse(courseID);
        if(course == null) {
            return true;
        } else {
            return false;
        }
    }
    @Override
    public void addCourse(Course course) throws AddCourseError {
        try {
            adminDao.addCourse(course);
        } catch (Exception e) {
            throw new AddCourseError("增加课程失败");
        }
    }

    @Override
    public Course findCourseById(Integer id) {
        return adminDao.selectCourseById(id);
    }

    @Override
    public void modifyCourse(Course course) {
        adminDao.updateCourse(course);
    }

    @Override
    public void removeCourse(Integer courseID) {
        adminDao.deleteCourse(courseID);
    }
}
